package com.lmt_9;

import java.util.*;
import java.util.function.Consumer;

public class Test {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("java1");
        list.add("java3");
        list.add("java2");
        list.add("java1");
        System.out.println(Arrays.toString(list.toArray()));

        HashSet<String> set = new HashSet<>();// 不可重复
        set.add("java1");
        set.add("java2");
        set.add("java3");
        set.add("java1");
        System.out.println(Arrays.toString(set.toArray()));

        Collection<String> c = new ArrayList<>();
        c.add("c");
        c.add("b");
        c.add("a");
        c.add("e");
        c.add("m");
        System.out.println(c);
        c.remove("a"); // 删除第一个出现的a
        System.out.println(c);
        System.out.println(c.contains("m")); // 判断是否包含
        Collection<String> m = new ArrayList<>();
        m.add("c");
        m.add("f");
        m.add("g");
        c.addAll(m); // 两个集合相加
        System.out.println(c);

//        c.clear();
//
//        System.out.println(c); // 清空

        System.out.println("========================");
        Iterator<String> it = c.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        for (String s: c){
            System.out.println(s);
        }
        c.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        c.forEach( s-> System.out.println(s));
        c.forEach( System.out::println);

    }

}
